<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="d1" style="width:300px;height:300px;background:red;">
        <div id="d2" style="width:100px;height:100px;background:purple"></div>
    </div>

<script>
    d1.onclick = function() {
        alert(1);
    }
    d2.onclick = function(e){
        alert(2);
        if(e.stopPropagation) {
            e.stopPropagation();//停止事件向上冒泡，不要触发上层事件
        }else{
            e.cancelBubble = true; //IE
        }
    }
</script>
</body>
</html>
